package io.renren.modules.seller.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.seller.entity.SeckillGoodsEntity;
import io.renren.modules.seller.service.SeckillGoodsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * @author hou 15373178086@163.com
 * @date 2020-02-16 11:30:48
 */
@RestController
@RequestMapping("seller/seckillgoods")
public class SeckillGoodsController {
    @Autowired
    private SeckillGoodsService seckillGoodsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:seckillgoods:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = seckillGoodsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:seckillgoods:info")
    public R info(@PathVariable("id") Long id) {
        SeckillGoodsEntity seckillGoods = seckillGoodsService.getById(id);

        return R.ok().put("seckillGoods", seckillGoods);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:seckillgoods:save")
    public R save(@RequestBody SeckillGoodsEntity seckillGoods) {
        seckillGoodsService.save(seckillGoods);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:seckillgoods:update")
    public R update(@RequestBody SeckillGoodsEntity seckillGoods) {
        ValidatorUtils.validateEntity(seckillGoods);
        seckillGoodsService.updateById(seckillGoods);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:seckillgoods:delete")
    public R delete(@RequestBody Long[] ids) {
        seckillGoodsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
